import 'package:shared_preferences/shared_preferences.dart';

class SpUtils {
  static const themeColor = "themeColor";
  static const appLocal = "appLocal";
  static const isFirstStart = "isFirstStart";
  static const userToken = "userToken";
  static const searchList = "searchList";

  static Future<bool> putInt(String key, int intNum) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.setInt(key, intNum);
  }

  static Future<int> getInt(String key) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getInt(key);
  }

  static Future<bool> putStringList(String key, var str) async {
    print('the str is $str');
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.setStringList(key, str);
  }

  static Future<List<String>> getStringList(String key) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getStringList(key);
  }

  static Future<bool> putString(String key, var str) async {
    print('the str is $str');
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.setString(key, str);
  }

  static Future<String> getString(String key) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getString(key);
  }

  static Future<bool> putBool(String key, bool value) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.setBool(key, value);
  }

  static Future<bool> getBool(String key) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getBool(key);
  }

  static remove(String key) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.remove(key);
  }
}

class PlayerPreference {
  static const String AUTO_PLAY = "autoPlay";

  static void saveAutoPlayValue(bool isAutoPlay) async {
    await SpUtils.putBool(AUTO_PLAY, isAutoPlay);
  }

  static Future<bool> getAutoPlayValue() async {
    return  await SpUtils.getBool(AUTO_PLAY);
  }
}
